﻿// 串行求pi
//

#include <iostream>
#include <chrono>

int main()
{
    const int N = 10000000;   // 区间个数
    const double dx = 1.0 / (double)N;    // 区间长度

    double pi = 0.0;
    double x = 0.0;

    auto t0 = std::chrono::high_resolution_clock::now();    // 开始时刻

    for (int i = 0; i < N; i++) {
        pi += 4.0 / (1 + x * x) * dx;
        x += dx;
    }

    auto t1 = std::chrono::high_resolution_clock::now();    // 结束时刻
    auto t = std::chrono::duration<double>(t1 - t0).count();

    // 输出结果
    std::cout << "pi = " << std::scientific << pi 
              << " , t = " << std::fixed << t << "\n";
}

